package com.ruoyi.web.petmall.petback.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.petmall.entity.AddressEntity;
import com.ruoyi.web.petmall.entity.UserEntity;
import com.ruoyi.web.petmall.petback.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/petBack/address")
@Api(tags = "地址管理")
public class AddressController extends BaseController {

    @Autowired
    private AddressService addressService;

    /**
     * 获取地址列表
     *
     * @param addressEntity 查询条件封装为 AddressEntity 对象
     * @return 包含地址列表的分页数据
     */
    @ApiOperation("分页查询用户地址")
    @GetMapping("/getAddressList")
    public TableDataInfo getAddressList(AddressEntity addressEntity) {
        startPage();
        List<AddressEntity> list = addressService.getAddressList(addressEntity);
        return getDataTable(list);
    }

    /**
     * 修改地址
     *
     * @param addressEntity 要修改的地址数据封装为 AddressEntity 对象
     * @return 包含操作结果的 AjaxResult 对象
     */
    @ApiOperation("修改地址")
    @PostMapping("/updateAddress")
    public AjaxResult updateAddress(@RequestBody AddressEntity addressEntity) {
        return toAjax(addressService.updateAddress(addressEntity));
    }

    /**
     * 删除地址
     *
     * @param id 要删除的地址 ID
     * @return 包含操作结果的 AjaxResult 对象
     */
    //TODO 删除地址
    @ApiOperation("删除地址")
    @DeleteMapping("/deleteAddress")
    public AjaxResult deleteAddress(Long id) {
        return toAjax(addressService.deleteAddress(id));
    }
}
